/**
 * 
 */
package com.demo2do.strawberry.web.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.demo2do.core.web.resolver.Secure;
import com.demo2do.strawberry.entity.user.UserRegister;
import com.demo2do.strawberry.entity.user.profile.Profile;
import com.demo2do.strawberry.service.UserService;

/**
 * @author lute
 *
 */
@Controller
@RequestMapping("")
public class UserController {
	
	@Autowired
	private UserService userService;
	

	/**
	 * @return
	 */
	@RequestMapping("/profile/edit")
	public String editProfile() {
		return "user/profile-edit";
	}

	/**
	 * 
	 * @param id
	 * @param profile
	 * @return
	 */
	@RequestMapping(value="/profile", method = RequestMethod.PATCH)
	public String onEditProfile(@Secure UserRegister userRegister, Profile profile) {

		userService.editProfile(userRegister, profile.getName(), profile.getDescription(), profile.getPhone(), profile.getRegion());
		
		return "redirect:/profile/edit";
	}

}
